import os


def cal_size(p):
    os.path.join(p)
    print("统计目录:", p)
    # 实际大小
    files_size = current_path_file_size(p)
    print("目录:\t" + p + "\n实际大小", str(files_size) + 'B')


def current_path_file_size(c_p):
    os.path.join(c_p)
    current_size = 0
    # 获取当前目录下所有文件
    for root, dirs, files in os.walk(os.path.abspath(c_p), topdown=False):
        # 遍历文件
        for name in files:
            current_size += os.path.getsize(root + os.sep + name)
            print("文件：" + name)
            print("地址:" + c_p + os.sep + name)
            print("大小：" + str(os.path.getsize(root + os.sep + name)) + "B")
            print("-------------------------------------------")
        # 遍历文件夹
        for dir_name in dirs:
            dir_size = current_path_file_size(root + os.sep + dir_name)
            current_size += dir_size
            print("文件夹：" + dir_name)
            print("地址：" + c_p + os.sep + dir_name)
            print("大小：" + str(dir_size) + "B")
            print("-------------------------------------------")
    return current_size


path = '/Users/zhaobowen/ai-learning/python'
cal_size(path)
